home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
misc
/
emu
/
ATUtilities.lha
/
ATUtilities
/
fi.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-09-26
|
17KB
|
711 lines
/* ******************************************************************* */
/* ** ** */
/* ** ATUtilities File Transfer ** */
/* ** Copright (C) 1992-1994 by Thomas Dreibholz ** */
/* ** All rights reserved ** */
/* ** ** */
/* ******************************************************************* */
#include "janus.h"
#include "ATUtilities.h"
UBYTE *FilePort="ATUtilities File Transfer";
UBYTE *PrefsName="AT:Prefs/FileTransfer.prefs";
UBYTE *HelpName="AT:Help/FileTransfer.help";
struct FilePrefs
{
UWORD Handles;
};
struct FilePrefs FilePrefs={150};
#define HANDLE_FILE 1
#define HANDLE_LOCK 2
#define HANDLE_FREE 0
#define HANDLE_USED 255
struct Handle
{
UBYTE HandleType;
UBYTE HandleControl;
APTR Address;
};
struct System
{
UWORD FreeHandles;
UWORD UsedHandles;
UWORD Handles;
ULONG SystemSize;
struct Handle Handle[2];
} *Sys;
#define SYSTEM_SIZE(x) (ULONG)(4L+(x*sizeof(struct Handle)))
struct NewDateStamp ti;
struct DirectoryEntry
{
UBYTE Name[30];
ULONG Size;
UWORD Protection;
UBYTE EntryType;
UBYTE Hour;
UBYTE Minute;
UBYTE Second;
UBYTE Day;
UBYTE Month;
UWORD Year;
};
#define MAX_ENTRIES (PUBLIC_PAGESIZE/sizeof(struct DirectoryEntry))
struct Directory
{
struct DirectoryEntry Entry[];
} *dirword,*dirbyte;
struct InfoBlock
{
ULONG NumSoftErrors;
ULONG UnitNumber;
ULONG DiskState;
ULONG NumBlocks;
ULONG NumBlocksUsed;
ULONG BytesPerBlock;
ULONG DiskType;
} *infoword;
struct JanusBase *JanusBase;
struct Library *GfxBase;
struct Library *IntuitionBase;
struct Library *ATUtilitiesBase;
struct AppManager *app;
struct Message *AppMessage;
struct ExtSetupSig *ExtSetupSig;
struct Window *WindowPtr;
struct RastPort *rp;
struct CommMemory *jhbyte,*jhword;
LONG JanusSignal;
LONG PortSignal;
ULONG JanusSignalMask;
ULONG PortSignalMask;
ULONG WaitSignalMask;
ULONG AppSignalMask;
ULONG Signale;
VOID HandleInt();
VOID ShowInfo();
VOID OpenAll();
VOID CloseAll();
BOOL EinstellungenAendern();
BOOL Valid();
WORD AllocHandle();
VOID FreeHandle();
struct MsgPort *Port;
/* Installationsroutine */
VOID main()
{
REGISTER UWORD i;
REGISTER BOOL bool;
OpenAll();
bool=FALSE;
while(bool==FALSE)
{
Signale=Wait(WaitSignalMask);
if(Signale & PortSignalMask)
{
i=Received(Port);
switch(i)
{
case UTILITY_CALL:
bool=EinstellungenAendern();
break;
case UTILITY_QUIT:
bool=ExitWarning();
break;
case UTILITY_INFO:
ShowInfo();
break;
case UTILITY_HELP:
Help(HelpName,0);
break;
}
}
if(Signale & JanusSignalMask)
{
HandleInt();
}
if(app!=NULL)
{
if(Signale & AppSignalMask)
{
AppMessage=GetMsg(app->Port);
if(AppMessage!=NULL)
{
ReplyMsg(AppMessage);
bool=EinstellungenAendern();
}
}
}
}
CloseAll();
}
/* PC-Befehle ausführen */
VOID HandleInt()
{
ULONG *ml;
REGISTER LONG l;
REGISTER WORD i;
REGISTER BOOL bool;
register struct FileHandle *fh;
register struct FileLock *lock,*lock2;
register struct FileInfoBlock *fib;
register struct InfoData *info;
switch(jhword->Arg1)
{
case 1000:
for(i=0;i<Sys->Handles;i++)
{
if((Valid(i,-1))==TRUE)
{
switch(Sys->Handle[i].HandleType)
{
case HANDLE_FILE:
Close(Sys->Handle[i].Address);
break;
case HANDLE_LOCK:
UnLock(Sys->Handle[i].Address);
break;
}
FreeHandle(i);
}
}
break;
case 0:
switch(jhword->Arg2)
{
case 1:
i=MODE_OLDFILE;
break;
case 2:
i=MODE_NEWFILE;
break;
default:
i=MODE_READWRITE;
break;
}
fh=Open(&jhbyte->Memory,i);
if(fh!=NULL)
{
i=AllocHandle();
if(i!=-1)
{
Sys->Handle[i].Address=fh;
Sys->Handle[i].HandleType=HANDLE_FILE;
jhword->Arg2=10000;
jhword->Arg3=i;
}
else
{
jhword->Arg2=50;
Close(fh);
}
}
else
{
jhword->Arg2=75;
}
break;
case 1:
if((Valid(jhword->Arg2,HANDLE_FILE))==TRUE)
{
switch(Sys->Handle[i].HandleType)
{
case HANDLE_FILE:
Close(Sys->Handle[jhword->Arg2].Address);
break;
}
FreeHandle(jhword->Arg2);
}
break;
case 2:
if((Valid(jhword->Arg2,HANDLE_FILE))==TRUE)
{
jhword->Arg2=Read(Sys->Handle[jhword->Arg2].Address,&jhbyte->Memory,jhword->Arg3);
} else jhword->Arg2=0;
break;
case 3:
if((Valid(jhword->Arg2,HANDLE_FILE))==TRUE)
{
jhword->Arg2=Write(Sys->Handle[jhword->Arg2].Address,&jhbyte->Memory,jhword->Arg3);
} else jhword->Arg2=0;
break;
case 7:
if((Valid(jhword->Arg2,HANDLE_FILE))==TRUE)
{
switch(jhword->Arg4)
{
case 1:
i=OFFSET_CURRENT;
break;
case 2:
i=OFFSET_END;
break;
default:
i=OFFSET_BEGINNING;
break;
}
l=Seek(Sys->Handle[jhword->Arg2].Address,jhword->Arg3,i);
ml=(ULONG *)jhword;
ml[0]=ConvertIntelMotorola(l);
jhword->Arg2=10000;
} else jhword->Arg2=0;
break;
case 9:
i=DeleteFile(&jhbyte->Memory);
if(i==0) jhword->Arg2=0; else jhword->Arg2=10000;
break;
case 10:
jhword->Arg2=IoErr();
break;
case 11:
lock=Lock(&jhbyte->Memory,ACCESS_READ);
if(lock!=NULL)
{
fib=AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR|MEMF_PUBLIC);
if(fib!=NULL)
{
l=0;
i=Examine(lock,fib);
while((i!=0) && (l<=MAX_ENTRIES))
{
strncpy(&dirbyte->Entry[l].Name,&fib->fib_FileName,30);
dirword->Entry[l].Protection=(UWORD)fib->fib_Protection;
if(fib->fib_DirEntryType<0) dirbyte->Entry[l].EntryType=0; else dirbyte->Entry[l].EntryType=1;
dirword->Entry[l].Size=ConvertIntelMotorola(fib->fib_Size);
ConvertDateStamp(&fib->fib_Date,&ti);
dirbyte->Entry[l].Hour=ti.Hour;
dirbyte->Entry[l].Minute=ti.Minute;
dirbyte->Entry[l].Second=ti.Second;
dirbyte->Entry[l].Day=ti.Day;
dirbyte->Entry[l].Month=ti.Month;
dirword->Entry[l].Year=ti.Year;
i=ExNext(lock,fib);
l++;
}
jhword->Arg2=10000;
jhword->Arg3=l-1;
FreeMem(fib,sizeof(struct FileInfoBlock));
}
else jhword->Arg2=75;
UnLock(lock);
}
else jhword->Arg2=50;
break;
case 12:
lock=Lock(&jhbyte->Memory,ACCESS_READ);
if(lock!=NULL)
{
i=AllocHandle();
if(i!=-1)
{
Sys->Handle[i].Address=lock;
Sys->Handle[i].HandleType=HANDLE_LOCK;
jhword->Arg2=10000;
jhword->Arg3=i;
}
else
{
jhword->Arg2=50;
UnLock(lock);
}
}
break;
case 13:
if((Valid(jhword->Arg2,HANDLE_LOCK))==TRUE)
{
UnLock(Sys->Handle[jhword->Arg2].Address);
FreeHandle(jhword->Arg2);
}
break;
case 14:
if((Valid(jhword->Arg2,HANDLE_LOCK))==TRUE)
{
lock=Sys->Handle[jhword->Arg2].Address;
fib=AllocMem(sizeof(struct FileInfoBlock),MEMF_CLEAR|MEMF_PUBLIC);
if(fib!=NULL)
{
Examine(lock,fib);
strcpy(&jhbyte->Memory[2000],&fib->fib_FileName);
lock2=ParentDir(lock);
if(lock2==NULL)
{
strcpy(&jhbyte->Memory,&fib->fib_FileName);
strcat(&jhbyte->Memory,":");
}
while(lock2!=NULL)
{
Examine(lock2,fib);
lock=ParentDir(lock2);
UnLock(lock2);
strcpy(&jhbyte->Memory,&fib->fib_FileName);
if(lock==NULL)
strcat(&jhbyte->Memory,":");
else
strcat(&jhbyte->Memory,"/");
strcat(&jhbyte->Memory,&jhbyte->Memory[2000]);
strcpy(&jhbyte->Memory[2000],&jhbyte->Memory);
lock2=lock;
}
FreeMem(fib,sizeof(struct FileInfoBlock));
}
jhword->Arg2=10000;
}
else jhword->Arg2=50;
break;
case 15:
if((Valid(jhword->Arg2,HANDLE_LOCK))==TRUE)
{
lock=Sys->Handle[jhword->Arg2].Address;
info=AllocMem(sizeof(struct InfoData),MEMF_CLEAR|MEMF_PUBLIC);
if(info!=NULL)
{
Info(lock,info);
infoword->NumSoftErrors=ConvertIntelMotorola(info->id_NumSoftErrors);
infoword->UnitNumber=ConvertIntelMotorola(info->id_UnitNumber);
infoword->DiskState=ConvertIntelMotorola(info->id_DiskState);
infoword->NumBlocks=ConvertIntelMotorola(info->id_NumBlocks);
infoword->NumBlocksUsed=ConvertIntelMotorola(info->id_NumBlocksUsed);
infoword->BytesPerBlock=ConvertIntelMotorola(info->id_BytesPerBlock);
infoword->DiskType=ConvertIntelMotorola(info->id_DiskType);
FreeMem(info,sizeof(struct InfoData));
jhword->Arg2=10000;
}
else jhword->Arg2=100;
}
else jhword->Arg2=50;
break;
case 16:
lock=Lock(&jhbyte->Memory,ACCESS_READ);
if(lock!=NULL)
{
lock2=CurrentDir(lock);
jhword->Arg2=10000;
}
else jhword->Arg2=50;
break;
case 17:
lock=CreateDir(&jhbyte->Memory);
if(lock!=NULL)
{
UnLock(lock);
jhword->Arg2=10000;
}
else jhword->Arg2=50;
break;
case 18:
i=Rename(&jhbyte->Memory,&jhword->Memory[1000]);
if(i==0) jhword->Arg2=0; else jhword->Arg2=10000;
break;
case 19:
i=Execute(&jhbyte->Memory,NULL,NULL);
if(i==0) jhword->Arg2=0; else jhword->Arg2=10000;
break;
}
SendJanusInt(26);
}
/* Installationsroutine */
VOID OpenAll()
{
REGISTER UWORD i;
register struct MsgPort *p;
register struct FileHandle *fh;
ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
if(ATUtilitiesBase==NULL)
{
printf("FEHLER: Kann ATUtilities-Library nicht öffnen.\n");
CloseAll();
}
GfxBase=OpenLibrary("graphics.library",0L);
IntuitionBase=OpenLibrary("intuition.library",0L);
if((GfxBase==NULL)||(IntuitionBase==NULL))
{
CloseAll();
}
p=FindPort(FilePort);
if(p!=NULL)
{
InfoRequest("ATUtilities File Transfer ist schon aktiv.");
CloseAll();
}
JanusBase=OpenLibrary("janus.library",0L);
if(JanusBase==NULL)
{
ErrorRequest(ERROR_JANUS);
CloseAll();
}
Port=CreatePort(FilePort,0L);
if(Port==NULL)
{
ErrorRequest(ERROR_MPORT);
CloseAll();
}
fh=Open(PrefsName,MODE_OLDFILE);
if(fh!=NULL)
{
Read(fh,&FilePrefs,sizeof(struct FilePrefs));
Close(fh);
}
Sys=AllocMem(SYSTEM_SIZE(FilePrefs.Handles),MEMF_CLEAR|MEMF_PUBLIC);
if(Sys==NULL)
{
ErrorRequest(ERROR_ALLOC);
CloseAll();
}
Sys->Handles=FilePrefs.Handles;
Sys->SystemSize=SYSTEM_SIZE(Sys->Handles);
Sys->FreeHandles=Sys->Handles;
ExtSetupSig=CreatePublicHandler(26);
if(ExtSetupSig==NULL)
{
CloseAll();
}
app=CreateAppItem("ATUtilities File Transfer");
if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
jhword=ExtSetupSig->WordAccess;
jhbyte=ExtSetupSig->ByteAccess;
dirword=infoword=jhword;
dirbyte=jhbyte;
PortSignal=Port->mp_SigBit;
PortSignalMask=(1L<<PortSignal);
JanusSignal=ExtSetupSig->JanusSignal;
JanusSignalMask=ExtSetupSig->JanusSignalMask;
WaitSignalMask=PortSignalMask+JanusSignalMask+AppSignalMask;
ChangeTaskPri(10);
}
/* Programmende */
VOID CloseAll()
{
if(app) DeleteAppItem(app);
if(Sys) FreeMem(Sys,Sys->SystemSize);
if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
if(Port) DeletePort(Port);
if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
if(GfxBase) CloseLibrary(GfxBase);
if(IntuitionBase) CloseLibrary(IntuitionBase);
if(JanusBase) CloseLibrary(JanusBase);
exit(0);
}
/* Einstellungsfenster */
BOOL EinstellungenAendern()
{
UBYTE tex[50];
REGISTER BOOL bool,ende;
REGISTER ULONG Class;
REGISTER UBYTE *integer;
register struct Window *win;
register struct Gadget *t1,*t2,*gad;
register struct IntuiMessage *msg;
register struct FileHandle *fh;
register struct RastPort *rp;
register struct TextFont *opal;
bool=FALSE;
win=CreateStdWindow("ATUtilities - File Transfer Einstellungen",
75,75,450,72+BorderHeight(),GADGETUP|CLOSEWINDOW,
WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE|GIMMEZEROZERO);
if(win!=NULL)
{
rp=win->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
CreateBoolGadget(win,10,5,155,12,"Einstellungen okay",1);
CreateBoolGadget(win,170,5,155,12,"Programm beenden",2);
CreateBoolGadget(win,335,5,50,12,"Info",3);
CreateBoolGadget(win,390,5,50,12,"Hilfe",4);
sprintf(&tex,"%ld",FilePrefs.Handles);
integer=CreateIntegerGadget(win,390,24,50,12,&tex,5,5);
SelectStdFPen(rp);
WriteText(rp,20,33,"Maximale Anzahl von Locks und Dateien:");
sprintf(&tex,"Aktuelle Anzahl von Handles: %ld",Sys->Handles);
WriteText(rp,20,45,&tex);
sprintf(&tex,"Aktuelle Anzahl freier Handles: %ld",Sys->FreeHandles);
WriteText(rp,20,55,&tex);
sprintf(&tex,"Aktuelle Anzahl belegter Handles: %ld",Sys->UsedHandles);
WriteText(rp,20,65,&tex);
ende=FALSE;
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
gad=msg->IAddress;
Class=msg->Class;
ReplyMsg(msg);
switch(Class)
{
case CLOSEWINDOW:
ende=TRUE;
break;
case GADGETUP:
switch(gad->GadgetID)
{
case 1:
FilePrefs.Handles=atol(integer);
if(FilePrefs.Handles<10) FilePrefs.Handles=10;
fh=Open(PrefsName,MODE_NEWFILE);
if(fh!=NULL)
{
Write(fh,&FilePrefs,sizeof(struct FilePrefs));
Close(fh);
}
ende=TRUE; bool=FALSE;
break;
case 2:
ende=TRUE; bool=TRUE;
break;
case 3:
ShowInfo();
break;
case 4:
Help(HelpName,0);
break;
}
break;
}
}
DeleteStdWindow(win);
}
if(bool==TRUE) bool=ExitWarning();
return(bool);
}
/* Information */
struct InfoItem ii1=
{
0,0
};
struct InfoItem ii2=
{
1,1,
"Service",
"Haben Sie Anregungen oder",
"Verbesserungswünsche?",
"",
"Senden Sie eine PM (Persönliche Mitteilung)",
"an T.DREIBHOLZ in folgenden Mailboxen:",
"",
"Carrier: 02261/75835",
"Apogee: 02262/68614",
"",
"oder schreiben Sie an:",
"",
"Thomas Dreibholz",
"Molbachweg 7",
"D-51674 Wiehl"
};
struct Info info=
{
2,
&ii1,
&ii2
};
VOID ShowInfo()
{
ExtInformationBox(NULL,
"ATUtilities File Transfer - Information",
"$VER: File Transfer - Version 4.0",
"Copyright (C) 1992-1994 by",
"Thomas Dreibholz",
"All rights reserved.",
"AT:Icons/Utility",&info);
}
/* Handle belegen */
WORD AllocHandle()
{
REGISTER UWORD i;
if(Sys->FreeHandles>0)
{
for(i=0;i<Sys->Handles;i++)
{
if(Sys->Handle[i].HandleControl==HANDLE_FREE)
{
Sys->Handle[i].HandleControl=HANDLE_USED;
Sys->UsedHandles++;
Sys->FreeHandles--;
return(i);
}
}
}
return(-1);
}
/* Handle freigeben */
VOID FreeHandle(num)
UWORD num;
{
Sys->Handle[num].HandleControl=HANDLE_FREE;
Sys->UsedHandles--;
Sys->FreeHandles++;
}
/* Prüfe Gültigkeit von Handle */
BOOL Valid(num,typ)
UWORD num;
WORD typ;
{
if((num<Sys->Handles) && (Sys->Handle[num].HandleControl==HANDLE_USED))
{
if(typ==-1) return(TRUE);
if(Sys->Handle[num].HandleType==(UBYTE)typ) return(TRUE);
}
return(FALSE);
}
/* Umwandung Intel <-> Motorola von Longwords */
#asm
public _ConvertIntelMotorola
_ConvertIntelMotorola:
move.l 4(sp),d0
swap d0
rts
#endasm